﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;

namespace Cqrs.Infrastructure
{
    public abstract class Event
    {
        public Event()
        {            
            DateStamp = DateTime.Now;            
        }

        public int Version;
        public DateTime DateStamp {set; get;}
        public Guid EventId { set; get; }

        public static Event ConvertJsonToEvent(string @event, Type eventType)
        {
            return (Event)JsonConvert.DeserializeObject(@event, eventType);
        }

        public static string ConvertEventToJson(Event @event)
        {
            return JsonConvert.SerializeObject(@event);
        }
    }
}
